import pymysql
from pyecharts.charts import Pie
from pyecharts import options

db = pymysql.connect(
    host="localhost",
    port=3306,
    user="root",
    database="crawlerdemo",
    password="748wxc946",
    charset="utf8"
)
cursor = db.cursor()
sql = ("SELECT job_place,(COUNT(*) * 100.0) / (SELECT COUNT(*) FROM job) AS work_percentage FROM  job GROUP BY job_place")
try:
    cursor.execute(sql)
    res = cursor.fetchall()
    pie = Pie()
    pie.add("%",res)
    pie.set_global_opts(title_opts=options.TitleOpts(title="各城市的岗位量占比"))
    pie.render("piera.html")
except:
    print("查询出错了")